package org.zoomdev.zoom;

public class TryWorkflow {

    private OuterHandler handler;

    private void handleException(JobData data, Throwable e) throws Throwable {
        if (data.state == State.FAIL) {
            handleFail(data);
        } else {
            throw e;
        }
    }

    private void handleFail(JobData data) {

    }

    private void handleSuccess(JobData data) {
        data.state = State.SUCCESS;
    }

    void retryJob(JobData data, int retryCount) throws Throwable {
        State state = handler.query(data);
        if (state == State.SUCCESS) {
            handleSuccess(data);
        } else if (state == State.FAIL) {
            handleFail(data);
        } else {
            throw new Exception();
        }
    }

    void handleJob(JobData data) throws Throwable {
        handler.handle(data);
        handleSuccess(data);
    }

    enum State {
        PROCESSING,
        SUCCESS,
        FAIL,
        UNKNOWN,

        TIMEOUT,
    }

    interface OuterHandler {
        void handle(JobData data) throws Exception;

        State query(JobData data) throws Exception;
    }

    class JobData {
        State state;
        private int id;
    }


}
